#include "stdafx.h"
#include "PermutationsUnitTests.h"
#include "Permutations.h"
#include "Permutation.h"
#include <iostream>
#include <bitset>
#include <sstream>

using namespace std;

// Check CountIntersection: count the intersection between 2 int arrays
TestUtils::TestResult CheckCountIntersection1() 
{
	unsigned long arrayA[11] = {0,1,2,3,4,5,6,7,8,9,10};
	unsigned long arrayB[11] = {10,9,8,7,6,5,4,3,2,1,11};
	//simple intersection: 10
	Permutation* per = new Permutation(arrayA, 4,11);
	int intersection = per->CountIntersection(arrayB);
	return TestUtils::VerifyIsTrue(intersection == 10,"Did not get right intersection size");	
}

// Check CountIntersection: count the intersection between 2 int arrays
TestUtils::TestResult CheckCountIntersection2() 
{
	unsigned long arrayA[6] = {13,54,555,100000000,16,77};
	unsigned long arrayB[6] = {10,1111111111,43,90,77,78};
	//simple intersection: 1
	Permutation* per = new Permutation(arrayA,32,6);
	int intersection = per->CountIntersection(arrayB);
	return TestUtils::VerifyIsTrue(intersection == 1,"Did not get right intersection size");	
}

// check transposing and returning a matrix
	TestUtils::TestResult CheckTranspose()
{
	unsigned long *ar = new unsigned long[10];
	unsigned long *cols;
	unsigned long *expectedCols = new unsigned long[4];
	unsigned long *rows;
	

	for (int i = 1; i <= 10; i++)
	{
		ar[i-1] = i;		
	}

	Permutation perm(ar,4,10);

	cols = perm.GetMatrixColumns();
	rows = perm.GetMatrixRows();
	
	expectedCols[0] = bitset<10>(string("0000000111")).to_ulong();
	expectedCols[1] = bitset<10>(string("0001111000")).to_ulong();
	expectedCols[2] = bitset<10>(string("0110011001")).to_ulong();
	expectedCols[3] = bitset<10>(string("1010101010")).to_ulong();

	stringstream s;

	for (int i = 0; i < 4; i++)
	{
		s.clear();
		s << i;
		
		if (TestUtils::VerifyIsTrue(expectedCols[i]==cols[i],"expected cols and cols differ at "+ s.str()) == TestUtils::TestFailed)
		{
			return TestUtils::TestFailed;
		}
	}

	for (int i = 0; i < 10; i++)
	{
				s.clear();
		s << i;
		if (TestUtils::VerifyIsTrue(ar[i]==rows[i],"original matrix and rows differ at " +s.str()) == TestUtils::TestFailed)
		{
			return TestUtils::TestFailed;
		}
	}
	return TestUtils::TestPassed;
}